package com.example.lyl.yuejian.view.home;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.lyl.yuejian.R;
import com.example.lyl.yuejian.bean.MasterDetialBean;
import com.example.lyl.yuejian.net.NetTool;

import butterknife.BindView;
import butterknife.ButterKnife;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.functions.Consumer;
import io.reactivex.schedulers.Schedulers;

public class MasterDetialActivity extends AppCompatActivity {

    @BindView(R.id.toolbar)
    Toolbar toolbar;
    @BindView(R.id.master_iv)
    ImageView masterIv;
    @BindView(R.id.dsmc_tv)
    TextView dsmcTv;
    @BindView(R.id.jj_tv)
    TextView jjTv;
    @BindView(R.id.nl_tv)
    TextView nlTv;
    @BindView(R.id.zjxw_tv)
    TextView zjxwTv;
    private int mid;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_master_detial);
        ButterKnife.bind(this);

        toolbar.setTitle("大师详情");
        setSupportActionBar(toolbar);
        ActionBar actionBar = getSupportActionBar();
        if (actionBar != null) {
            actionBar.setDisplayHomeAsUpEnabled(true);
        }

        Intent intent = getIntent();
        mid = intent.getIntExtra("mid" , 0);

        NetTool.getInstance().getApi()
                .masterDetialRequest(mid)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Consumer<MasterDetialBean>() {
                    @Override
                    public void accept(MasterDetialBean masterDetialBean) throws Exception {
                        Glide.with(MasterDetialActivity.this).load("http://" +
                        masterDetialBean.getData().getMpic()).placeholder(R.mipmap.lunbo3)
                                .into(masterIv);
                        dsmcTv.setText("大师名称:  " + masterDetialBean.getData().getMname());
                        jjTv.setText("简介:  " + masterDetialBean.getData().getMintro());
                        zjxwTv.setText("最近新闻  " + masterDetialBean.getData().getNews());
                        nlTv.setText("年龄:  " + masterDetialBean.getData().getMage());
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {

                    }
                });


    }


    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case android.R.id.home:
                finish();
                break;
        }
        return true;
    }
}
